import cv2 as cv
import numpy as np

cap = cv.VideoCapture(0)
width = 1280  # 定义摄像头获取图像宽度
height = 960  # 定义摄像头获取图像长度
fps = 60
cap.set(6, cv.VideoWriter_fourcc('M', 'J', 'P', 'G')) # 设置图像的编码格式
cap.set(cv.CAP_PROP_FPS, fps)  # 帧率
cap.set(cv.CAP_PROP_FRAME_WIDTH, width)  # 设置宽度
cap.set(cv.CAP_PROP_FRAME_HEIGHT, height)  # 设置高度
i = 0
while(cap.isOpened()):
    ret, frame = cap.read()
    if not ret:
        print("Can't receive frame (stream end?). Exiting ...")
        break
    cv.imshow('cali_frame', frame)

    key = cv.waitKey(1)

    if key == ord('q'):
        break

    if key == ord('s'):
        cv.imwrite('cali_pic_'+str(i)+'.jpg', frame)
        i = i+1

cap.release()
cv.destroyAllWindows()